import java.util.Arrays;

public class PrimeNumber {
    public static boolean[] sieveOfEratosthenes(int max) {
        boolean[] isPrime = new boolean[max + 1];
        Arrays.fill(isPrime, true);
        if (max >= 0) isPrime[0] = false;
        if (max >= 1) isPrime[1] = false;

        for (int i = 2; i * i <= max; i++) {
            if (isPrime[i]) {
                for (int j = i * i; j <= max; j += i) {
                    isPrime[j] = false;
                }
            }
        }
        return isPrime;
    }

    public static void main(String[] args) {
        int limit = 20000;
        boolean[] isPrime = sieveOfEratosthenes(limit);
        int count = 0;

        for (int i = 2; i <= limit; i++) {
            if (isPrime[i]) {
                System.out.printf("%-6d", i);
                count++;

                if (count % 5 == 0) {
                    System.out.println();
                }
            }
        }

        if (count % 5 != 0) {
            System.out.println();
        }
    }
}